package com.qiyeji.real_estate.controller;

import com.qiyeji.real_estate.entity.projectPhase;
import com.qiyeji.real_estate.service.ProjectPhaseService;
import com.qiyeji.real_estate.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/ProjectPhase")
@RestController
@ResponseBody
public class ProjectPhaseController {
    @Autowired
    ProjectPhaseService projectPhaseService;

    @PostMapping("/getAllProjectPhase")
    public Result getAllProjectPhase() {
        List<projectPhase> projectPhase = projectPhaseService.getAllProjectPhase();
        if(projectPhase==null) {
            return Result.error();
        }
        else {
            return Result.success(projectPhase);
        }
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody projectPhase projectPhase){
        int res=projectPhaseService.insert(projectPhase);
        if(res==0) {
            return Result.error();
        }
        else {
            return Result.success(res);
        }
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Map<String,String> params){
        String key=params.get("key");
        int res=projectPhaseService.delete(key);
        if(res==0){
            return Result.error();
        }else{
            return Result.success(res);
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody projectPhase projectPhase){
        int res=projectPhaseService.updateByPrimaryKey(projectPhase);
        if(res==0){
            return Result.error();
        }else{
            return Result.success(res);
        }
    }

    @PostMapping("/selectById")
    public Result selectById(@RequestBody Map<String,String> params){
        String key=params.get("key");
        projectPhase projectPhase=projectPhaseService.selectByPrimaryKey(key);
        if(projectPhase==null){
            return Result.error();
        }else{
            return Result.success(projectPhase);
        }
    }

    @PostMapping("/fuzzyQuery")
    public Result fuzzyQuery(@RequestBody Map<String,String> params){
        String key = params.get("key");
        List<projectPhase> projectPhase = projectPhaseService.fuzzyQuery(key);
        if(projectPhase==null) {
            return Result.error();
        }
        else {
            return Result.success(projectPhase);
        }
    }
}
